<template>
  <div class="container">
    <div class="header">
      <h1>系统设置</h1>
    </div>
    
    <el-card class="setting-card">
      <el-tabs v-model="activeTab" type="border-card">
        <!-- 小程序设置 -->
        <el-tab-pane label="小程序设置" name="miniapp">
          <el-form :model="miniappForm" label-width="120px" class="setting-form">
            <el-form-item label="小程序名称">
              <el-input v-model="miniappForm.name" placeholder="请输入小程序名称"></el-input>
            </el-form-item>
            
            <el-form-item label="小程序AppID">
              <el-input v-model="miniappForm.appId" placeholder="请输入小程序AppID"></el-input>
            </el-form-item>
            
            <el-form-item label="小程序AppSecret">
              <el-input v-model="miniappForm.appSecret" placeholder="请输入小程序AppSecret" type="password" show-password></el-input>
            </el-form-item>
            
            <el-form-item label="显示模式">
              <el-radio-group v-model="miniappForm.displayMode">
                <el-radio :label="1">默认模式</el-radio>
                <el-radio :label="2">隐藏模式</el-radio>
              </el-radio-group>
            </el-form-item>
            
            <el-form-item label="主页欢迎语">
              <el-input v-model="miniappForm.welcomeText" type="textarea" rows="3"></el-input>
            </el-form-item>
            
            <el-form-item label="小程序主图">
              <el-upload
                action="/api/upload"
                list-type="picture-card"
                :limit="1"
                :file-list="miniappImages"
              >
                <el-icon><Plus /></el-icon>
              </el-upload>
            </el-form-item>
            
            <el-form-item>
              <el-button type="primary" @click="saveMiniapp">保存设置</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        
        <!-- 系统参数设置 -->
        <el-tab-pane label="系统参数设置" name="system">
          <el-form :model="systemForm" label-width="120px" class="setting-form">
            <el-form-item label="系统标题">
              <el-input v-model="systemForm.title" placeholder="请输入系统标题"></el-input>
            </el-form-item>
            
            <el-form-item label="Logo图片">
              <el-upload
                action="/api/upload"
                list-type="picture-card"
                :limit="1"
                :file-list="logoImages"
              >
                <el-icon><Plus /></el-icon>
              </el-upload>
            </el-form-item>
            
            <el-form-item label="系统版本">
              <el-input v-model="systemForm.version" placeholder="请输入系统版本"></el-input>
            </el-form-item>
            
            <el-form-item label="ICP备案号">
              <el-input v-model="systemForm.icp" placeholder="请输入ICP备案号"></el-input>
            </el-form-item>
            
            <el-form-item label="客服电话">
              <el-input v-model="systemForm.servicePhone" placeholder="请输入客服电话"></el-input>
            </el-form-item>
            
            <el-form-item label="版权信息">
              <el-input v-model="systemForm.copyright" placeholder="请输入版权信息"></el-input>
            </el-form-item>
            
            <el-form-item>
              <el-button type="primary" @click="saveSystem">保存设置</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <!-- 轮播图设置 -->
        <el-tab-pane label="轮播图设置" name="banner">
          <div class="settings-redirect-container">
            <div class="settings-info-box">
              <el-icon class="settings-icon"><Picture /></el-icon>
              <h3>轮播图设置</h3>
              <p>在此设置小程序轮播图，包括添加、修改、删除轮播图及其显示顺序。</p>
              <el-button type="primary" @click="goToBannerSettings">管理轮播图</el-button>
            </div>
          </div>
        </el-tab-pane>

        <!-- 模块管理 -->
        <el-tab-pane label="首页模块管理" name="modules">
          <div class="settings-redirect-container">
            <div class="settings-info-box">
              <el-icon class="settings-icon"><Grid /></el-icon>
              <h3>小程序首页模块管理</h3>
              <p>在此设置小程序首页模块的显示顺序和可见性，通过拖拽调整显示顺序。</p>
              <el-button type="primary" @click="goToModuleSettings">管理首页模块</el-button>
            </div>
          </div>
        </el-tab-pane>

        <!-- 积分设置 -->
        <el-tab-pane label="积分设置" name="points">
          <div class="settings-redirect-container">
            <div class="settings-info-box">
              <el-icon class="settings-icon"><Coin /></el-icon>
              <h3>积分系统设置</h3>
              <p>在此设置用户积分获取规则，包括签到奖励、连续签到积分、邀请好友奖励等设置。</p>
              <el-button type="primary" @click="goToPointsSettings">前往积分设置</el-button>
              <el-button @click="goToPointsList" style="margin-left: 10px">用户积分管理</el-button>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Plus, Coin, Picture, Grid } from '@element-plus/icons-vue'

const router = useRouter()
const activeTab = ref('miniapp')

// 小程序设置
const miniappForm = reactive({
  name: '宏益学习',
  appId: 'wx12345678',
  appSecret: '******',
  displayMode: 1,
  welcomeText: '欢迎使用宏益学习小程序'
})

const miniappImages = ref([
  {
    name: 'miniapp-main.png',
    url: 'https://placeholder.pics/svg/200x200'
  }
])

// 系统参数设置
const systemForm = reactive({
  title: '宏益后台管理系统',
  version: 'v1.0.0',
  icp: '粤ICP备12345678号',
  servicePhone: '400-123-4567',
  copyright: '© 2023 宏益科技有限公司'
})

const logoImages = ref([
  {
    name: 'logo.png',
    url: 'https://placeholder.pics/svg/200x60'
  }
])

// 保存小程序设置
const saveMiniapp = () => {
  // 实现保存逻辑
  ElMessage.success('小程序设置保存成功')
}

// 保存系统设置
const saveSystem = () => {
  // 实现保存逻辑
  ElMessage.success('系统参数设置保存成功')
}

// 获取设置数据
const fetchSettings = () => {
  // 实现获取设置数据的逻辑
}

// 跳转到轮播图设置页面
const goToBannerSettings = () => {
  router.push('/settings/banner')
}

// 跳转到积分设置页面
const goToPointsSettings = () => {
  router.push('/settings/points')
}

// 跳转到积分列表页面
const goToPointsList = () => {
  router.push('/settings/points-list')
}

// 跳转到模块设置页面
const goToModuleSettings = () => {
  router.push('/settings/modules')
}

onMounted(() => {
  fetchSettings()
})
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
  
  .header {
    margin-bottom: 20px;
    
    h1 {
      font-size: 24px;
      margin: 0;
    }
  }
  
  .setting-card {
    margin-bottom: 20px;
  }
  
  .setting-form {
    max-width: 600px;
    margin-top: 20px;
  }

  .settings-redirect-container {
    padding: 20px 0;
    max-width: 600px;
    
    .settings-info-box {
      padding: 30px;
      border: 1px solid #ebeef5;
      border-radius: 8px;
      background-color: #f9fafc;
      text-align: center;
      
      .settings-icon {
        font-size: 48px;
        color: #409eff;
        margin-bottom: 15px;
      }
      
      h3 {
        font-size: 18px;
        margin-bottom: 15px;
      }
      
      p {
        color: #606266;
        margin-bottom: 20px;
      }
    }
  }
}
</style> 